//app.js是项目的入口文件

const Koa = require("koa2");//构造函数
const Router = require("koa-router");//路由
const app = new Koa();//生命实力
const router = new Router();
const port = 3000;

// 设置路由
router.get("/", async (ctx, next) => {
  ctx.body = '首页'
})
router.get("/info", async (ctx, next) => {
  ctx.body = '详情'
})

// router.routes() 启动路由
// router.allowedMethods() 允许所有请求
app.use(router.routes(), router.allowedMethods())

//调用中间件
app.use(async (ctx) => {
  ctx.response.body = 'hello world'
});

//监听端口
app.listen(port, () => {
  console.log(`Serve is running athttp://localhost:${port}`)
})//监听3000端口3000